<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.7
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############










if(get('sorted')==1){
    foreach($_POST['css'] as $sort=>$keyname){
        $keyname = preg_replace('/[^a-zA-Z0-9]/', '', $keyname);
        if($DB->countRows($CONFIG->dbprefix.'jfxcss_stylesheets', "keyname = '{$keyname}' AND is_default = 1")>0){
            $DB->update($CONFIG->dbprefix.'jfxcss_stylesheets', array('sorting'=>$sort), "keyname = '{$keyname}' AND is_default = 1");
        }
    }
    exit;
}









$VIEW->addJs('
$(document).ready(function(){
     var sortableStop = function(){

        var sorted = $("#jfxcss-sortable").sortable("serialize");
        //alert(sorted);
        //$("#jfx-sort-pages").css("display", "none");
        //$("#jfx-workspace-inner").get(0).innerHTML = \'<div align="center"><img src="'.$CONFIG->imageUrl.'/admin/loadingAnimation.gif" alt="Loading..." /></div>\';
        $.post("'.$this->adminUrl.'/sort-default-stylesheets/?sorted=1", sorted, function(){});
    }
    $("#jfxcss-sortable").sortable({cursor : "pointer", stop : sortableStop });
});
');






$css = $DB->fetchAll("SELECT * FROM {$CONFIG->dbprefix}jfxcss_stylesheets WHERE is_default = 1 ORDER BY sorting ASC");

echo '<ul id="jfxcss-sortable">';
foreach($css as $k=>$v){
    echo '<li id="css_'.$v['keyname'].'">'.$this->getContentLang('title', $v['keyname']).'</li>';
}
echo '</ul>';









